//
//  BaseTableViewController.swift
//  SinaBlog
//
//  Created by ChenWei on 15/10/3.
//  Copyright © 2015年 cw. All rights reserved.
//

import UIKit

class BaseTableViewController: UITableViewController, VistorViewDelegate {

    /// 定义属性记录当前是否登陆
    var isLogin : Bool = (UserAccount.loadAccount() != nil)
    
    /// 定义属性保存自定义的访客视图
    var vistorView : VistorView?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // 判断当前是否登陆,返回对应的view
        view = isLogin ? self.view : setupVistorView()

    }
    
    // MARK: - 设置访客界面
    
    func setupVistorView()-> VistorView {
        
        // 创建访客界面
        vistorView = VistorView()
       
        // 设置代理
        vistorView!.deletage = self
        
        // 设置导航条
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: Selector("vistorViewDidRegigterBtnClick:"))

        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登陆", style: UIBarButtonItemStyle.Plain, target: self, action: Selector("vistorViewDidLoginBtnClick:"))
        
        return vistorView!
    }

    // MRRK: - VistorViewDelegate
    func vistorViewDidLoginBtnClick(vistorView: VistorView) {
        let oAuthVC = OAuthViewController()
        let nav = UINavigationController(rootViewController: oAuthVC)
        
        presentViewController(nav, animated: true, completion: nil)
    }
    
    func vistorViewDidRegigterBtnClick(vistorView: VistorView) {
        NSLog( "")
    }
}



     